package com.zx.wangyixinwen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zx.wangyixinwen.R;
import com.zx.wangyixinwen.bean.Jokes;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class JokesAdapter extends BaseAdapter{
    private Context context;
    private List<Jokes> datas;

    public JokesAdapter(Context context, List<Jokes> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return null == datas ? 0 :datas.get(0).get段子().size();
    }

    @Override
    public Object getItem(int position) {
        return  datas.size() > 0 && datas != null ? datas.size() : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_jockes_adapter,null);
            holder = new ViewHolder();
            holder.body = (TextView) convertView.findViewById(R.id.tv_item_jockes);
            holder.up = (TextView) convertView.findViewById(R.id.upTimes);
            holder.down = (TextView) convertView.findViewById(R.id.downTimes);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.body.setText(datas.get(0).get段子().get(position).getDigest());
        holder.up.setText(String.valueOf(datas.get(0).get段子().get(position).getUpTimes()));
        holder.down.setText(String.valueOf(datas.get(0).get段子().get(position).getDownTimes()));
        return convertView;
    }



    class ViewHolder{
            private TextView body, up, down;

    }
}
